/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package edu.wpi.first.wpilibj.templates.commands;

import edu.wpi.first.wpilibj.smartdashboard.SmartDashboard;
import edu.wpi.first.wpilibj.templates.RobotTemplate;


/**
 *
 * @author Robotics
 */
public class TimedLaunchCatapult extends CommandBase{
    
    private double Duration = 0.0; //0.055
    private double MotorSpeed = 0.0; //1.0
    private boolean firstTime = true;
    private boolean autonomousMode = false;
    
    public TimedLaunchCatapult(boolean autoCalled){
        // Use requires() here to declare subsystem dependencies
        // eg. requires(chassis);
        requires(catapult);
        autonomousMode = autoCalled;
        
        //Duration = SmartDashboard.getNumber("Catapult Duration: ", 0.25);
        //MotorSpeed = SmartDashboard.getNumber("Catapult Speed: ", 0.25);
    }

    // Called just before this Command runs the first time
    protected void initialize(){
        if(autonomousMode){
            Duration = 0.055;
            MotorSpeed = 1.0;
        }else{
            Duration = SmartDashboard.getNumber("Catapult Duration: ", 0.055);
            MotorSpeed = SmartDashboard.getNumber("Catapult Speed: ", 1.0);
        }
        SmartDashboard.putNumber("Catapult Duration: ", Duration);
        SmartDashboard.putNumber("Catapult Speed: ", MotorSpeed);
        setTimeout(Duration);
        firstTime = true;
    }

    // Called repeatedly when this Command is scheduled to run
    protected void execute(){
        if(firstTime){
            catapult.setMotorSpeeds(-MotorSpeed);
            firstTime = false;
        }
        catapult.updateEncoders();
    }

    // Make this return true when this Command no longer needs to run execute()
    protected boolean isFinished() {
        return isTimedOut();
    }

    // Called once after isFinished returns true
    protected void end(){
        catapult.stopMotors();
        catapult.resetEncoder();
    }

    // Called when another command which requires one or more of the same
    // subsystems is scheduled to run
    protected void interrupted() {
    }
}
